package lexer;

/**
 * 词法分析得到的Token
 */
public class Token {
    private TokenType tokenType;
    private Object tokenValue; // int 或者 String
    private int line;
    public Token(TokenType tokenType, Object value, int line) {
        this.tokenType = tokenType;
        this.tokenValue = value;
        this.line=line;
    }

    public boolean equalTo(String s) {
        return tokenValue.equals(s);
    }

    public TokenType type() {
        return tokenType;
    }

    public Object value() {
        return tokenValue;
    }

    @Override
    public String toString() {
        return "Token{" +
                "tokenType=" + tokenType +
                ", tokenValue=" + tokenValue +
                ", line=" + line +
                '}';
    }

    public boolean isOperator() {// * / % + - < <= > >= == != ! && ||
        boolean res = false;
        switch (tokenType) {
            case Mult:
            case Div:
            case Modulo:
            case Plus:
            case Minus:
            case Lt:
            case Lte:
            case Gt:
            case Gte:
            case Eq:
            case NEq:
            case Not:
            case And:
            case Or:
                res = true;
                break;
        }
        return res;
    }
}
